package com.hengxinguotong.zhihuichengjian.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.hengxinguotong.zhihuichengjian.R;
import com.hengxinguotong.zhihuichengjian.bean.GroupBean;
import com.hengxinguotong.zhihuichengjian.widget.font.HXTextView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by liux on 2016/7/11.
 */
public class GroupListAdapter extends BaseAdapter {

    private List<GroupBean> groupInfos;
    private final Context context;

    public GroupListAdapter(Context context,List<GroupBean> groupInfos ) {
        this.context = context;
        this.groupInfos = groupInfos;
    }

    @Override
    public int getCount() {
        return groupInfos.size();
    }

    @Override
    public Object getItem(int position) {
        return groupInfos.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null || convertView.getTag() == null) {
            convertView = LayoutInflater.from(parent.getContext())
                    .inflate(R.layout.item_group, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        GroupBean groupBean=groupInfos.get(position);
        holder.groupnameTv.setText(groupBean.getName());
        holder.groupcountTv.setText("("+groupBean.getCount()+")");
        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.group_iv)
        ImageView groupIv;
        @BindView(R.id.groupname_tv)
        HXTextView groupnameTv;
        @BindView(R.id.groupcount_tv)
        HXTextView groupcountTv;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}

